package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.DicAirportStation;
import com.ktgj.hotel.service.IDicAirportStationService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-12-09
 */
@ControllerAdvice
@RestController
@RequestMapping("/airportStation")
public class DicAirportStationController extends BaseController
{
    @Autowired
    private IDicAirportStationService dicAirportStationService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:station:list")
    @GetMapping("/list")
    public TableDataInfo list(DicAirportStation dicAirportStation)
    {
        startPage();
        List<DicAirportStation> list = dicAirportStationService.selectDicAirportStationList(dicAirportStation);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:station:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DicAirportStation dicAirportStation) throws IOException
    {
        List<DicAirportStation> list = dicAirportStationService.selectDicAirportStationList(dicAirportStation);
        ExcelUtil<DicAirportStation> util = new ExcelUtil<DicAirportStation>(DicAirportStation.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "hotel:station:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dicAirportStationService.selectDicAirportStationById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:station:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DicAirportStation dicAirportStation)
    {
        return toAjax(dicAirportStationService.insertDicAirportStation(dicAirportStation));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:station:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DicAirportStation dicAirportStation)
    {
        return toAjax(dicAirportStationService.updateDicAirportStation(dicAirportStation));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:station:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dicAirportStationService.deleteDicAirportStationByIds(ids));
    }

    /**
     * 根据市查询酒店筛选条件“火车站”
     * */
    @PostMapping("/conditionTrainStation")
    public AjaxResult conditionTrainStation(@RequestBody Map<String, Object> map){
        Long cityId = Long.valueOf(map.get("cityId").toString());
        Long typeId = Long.valueOf(map.get("typeId").toString());
        List<DicAirportStation> dicAirportStationList;
        try {
            dicAirportStationList = dicAirportStationService.dicAirportStationList(cityId, typeId);
            if (dicAirportStationList != null && dicAirportStationList.size() > 0){
                return AjaxResult.success(dicAirportStationList);
            }
            else {
                return AjaxResult.error("未查到该地区的火车站信息");
            }
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }
}
